/*
 *  xmlHandler.cpp
 *  initiativeTracker
 *
 *  Created by Sam Jaffe on 5/9/12.
 *  Copyright 2012 WPI. All rights reserved.
 *
 */

#include "xmlHandler.h"
#include <xercesc/framework/MemBufInputSource.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/validators/common/Grammar.hpp>
#include <xercesc/util/XMLUni.hpp>

XML_Handler::XML_Handler() : parser() {
    xercesc::XMLPlatformUtils::Initialize();
}

XML_Handler::XML_Handler(const std::string schema) : XML_Handler() {
    parser.loadGrammar((XMLCh*) schema.c_str(), 
                       xercesc::Grammar::SchemaGrammarType, true);
    parser.useCachedGrammarInParse(true);
}

XML_Handler::~XML_Handler() {
    xercesc::XMLPlatformUtils::Terminate();
}

void XML_Handler::parse(const std::string xml) {
    xercesc::MemBufInputSource is((XMLByte*) xml.c_str(), xml.size(),
                                  "xml (in memory)");
    parser.parse(is);
}

xercesc::DOMDocument* XML_Handler::getDocument() {
    return parser.getDocument();
}
